# Plots Berry curvature spectrum

from math import pi
import numpy as np
hbar=0.652
def inputparsing():

    from optparse import OptionParser

    parser = OptionParser()

    parser.add_option("--tp",          action="store",type="float", default="20",       help="[%default fs]")
    parser.add_option("--eigfile",     action="store",type="string",default="eig.dat",  help="[%default fs]")
    parser.add_option("--netbcfile",   action="store",type="string",default="bnet.dat", help="[%default fs]")
    parser.add_option("--kfile",       action="store",type="string",default="kfile.dat",help="[%default fs]")
    parser.add_option("--ic",          action="store",type=int,     default=None,       help="[%default fs]")
    parser.add_option("--nw",          action="store",type=int,     default=10,         help="[%default fs]")
    parser.add_option("--fac",         action="store",type=int,     default=1,          help="[%default]")
    op,args=parser.parse_args()

    return op

if __name__=="__main__":

    op=inputparsing()

    E = np.loadtxt(op.eigfile).T
    B = np.loadtxt(op.netbcfile)
    k = np.loadtxt(op.kfile)
    B = B[:,0:op.ic]

    dk = k[1,0]-k[0,0]

    Ec  = E[:,op.ic].reshape((E.shape[0],1))
    print 'min Ec: ',np.min(Ec)
    dE  = np.kron(Ec,np.ones((1,op.ic)))
    dE -= E[:,0:op.ic]
    dE -= np.min(dE)
    print 'shape',dE.shape
    w = np.linspace(0,0.5,100)
    g = np.zeros((w.shape[0],op.ic))
    
    j=-1
    for u in w:
        j+=1
        f = np.exp(-((dE-u)*op.tp/hbar)**2) #*op.tp*pi/2;
        
        g[j,:] = np.sum(B*f**2,axis=0)*dk**2;

    g *= op.fac * (0.5625)**2

    g = np.hstack((w.reshape((w.shape[0],1)),g,np.sum(g,axis=1).reshape((w.shape[0],1))))
    print 'result array shape:',g.shape
    print 'final column is the sum'
    np.savetxt('injectedbc.dat',g)

    
    
